package com.heima.ThreadPool.ExecutorService3ways;

import java.util.concurrent.*;

/**
 * @Author: Ethan Yankang
 * @Program: 面试必会代码
 * @Date: 2024-08-29 11:15
 **/
public class newFixedThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService es = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 10; i++) {
            final int taskId=i;
            es.submit(()-> System.out.println("线程"+Thread.currentThread().threadId()+"is running,taskId="+taskId));

//            FutureTask<String> stringFutureTask = new FutureTask<String>(()-> {
//                System.out.println("线程"+Thread.currentThread().threadId()+"is running,taskId="+taskId);
//                return "taskId="+taskId;
//            });
//            es.submit(stringFutureTask);
//            System.err.println(stringFutureTask.get());
        }
    }
}

/*
*原理仍然是7参数祖师爷来的
public static ExecutorService newFixedThreadPool(int nThreads) {
        return new ThreadPoolExecutor(nThreads, nThreads,
                                      0L, TimeUnit.MILLISECONDS,
                                      new LinkedBlockingQueue<Runnable>());
    }
*/